package se.teamscape.client.gin;

import net.customware.gwt.presenter.client.DefaultEventBus;
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.gin.AbstractPresenterModule;
import net.customware.gwt.presenter.client.place.ParameterTokenFormatter;
import net.customware.gwt.presenter.client.place.PlaceManager;
import net.customware.gwt.presenter.client.place.TokenFormatter;
import se.teamscape.client.place.BasicPlaceManager;
import se.teamscape.client.presenter.AppPresenter;
import se.teamscape.client.presenter.CenterContainerPresenter;
import se.teamscape.client.presenter.EastContainerPresenter;
import se.teamscape.client.presenter.EditDataPresenter;
import se.teamscape.client.presenter.EditPersonPresenter;
import se.teamscape.client.presenter.ListModelsPresenter;
import se.teamscape.client.presenter.ListPlayersPresenter;
import se.teamscape.client.presenter.ListTeamsPresenter;
import se.teamscape.client.presenter.LoginPresenter;
import se.teamscape.client.presenter.NavigationPresenter;
import se.teamscape.client.presenter.NorthContainerPresenter;
import se.teamscape.client.presenter.ShowDataPresenter;
import se.teamscape.client.presenter.ShowPersonPresenter;
import se.teamscape.client.presenter.SouthContainerPresenter;
import se.teamscape.client.presenter.WelcomePresenter;
import se.teamscape.client.presenter.WestContainerPresenter;
import se.teamscape.client.rpc.CachingDispatchAsync;
import se.teamscape.client.view.AppView;
import se.teamscape.client.view.CenterContainerView;
import se.teamscape.client.view.EastContainerView;
import se.teamscape.client.view.EditDataView;
import se.teamscape.client.view.ListModelsView;
import se.teamscape.client.view.LoginView;
import se.teamscape.client.view.NavigationView;
import se.teamscape.client.view.NorthContainerView;
import se.teamscape.client.view.ShowDataView;
import se.teamscape.client.view.SouthContainerView;
import se.teamscape.client.view.WelcomeView;
import se.teamscape.client.view.WestContainerView;

import com.google.inject.Singleton;

/**
 * Bindings for GIN
 * 
 * @author Andreas Borglin
 * 
 */
public class TeamScapeClientModule extends AbstractPresenterModule {

    @Override
    protected void configure() {

        // Bind our singletons
        bind(EventBus.class).to(DefaultEventBus.class).in(Singleton.class);

        // Bind place handling stuff
        // install(new PresenterSetupModule(BasicPlaceManager.class));
        bind(TokenFormatter.class).to(ParameterTokenFormatter.class);
        bind(PlaceManager.class).to(BasicPlaceManager.class).asEagerSingleton();

        // Bind presenters and views

        // For generic views, we have to bind displays separately from
        // presenters
        // to avoid binding them several times
        bindDisplay(ShowDataPresenter.Display.class, ShowDataView.class);
        bindDisplay(EditDataPresenter.Display.class, EditDataView.class);
        bindDisplay(ListModelsPresenter.Display.class, ListModelsView.class);

        // Bind presenters only
        bind(ShowPersonPresenter.class).in(Singleton.class);
        bind(EditPersonPresenter.class).in(Singleton.class);
        bind(ListTeamsPresenter.class).in(Singleton.class);
        bind(ListPlayersPresenter.class).in(Singleton.class);

        // For 1-1 presenter/view mapping, we use bindPresenter directly
        bindPresenter(LoginPresenter.class, LoginPresenter.Display.class, LoginView.class);
        bindPresenter(NavigationPresenter.class, NavigationPresenter.Display.class, NavigationView.class);
        bindPresenter(WelcomePresenter.class, WelcomePresenter.Display.class, WelcomeView.class);

        bindPresenter(EastContainerPresenter.class, EastContainerPresenter.Display.class, EastContainerView.class);
        bindPresenter(WestContainerPresenter.class, WestContainerPresenter.Display.class, WestContainerView.class);
        bindPresenter(NorthContainerPresenter.class, NorthContainerPresenter.Display.class, NorthContainerView.class);
        bindPresenter(SouthContainerPresenter.class, SouthContainerPresenter.Display.class, SouthContainerView.class);
        bindPresenter(CenterContainerPresenter.class, CenterContainerPresenter.Display.class, CenterContainerView.class);

        bindPresenter(AppPresenter.class, AppPresenter.Display.class, AppView.class);

        // Bind so we can inject in our presenters
        bind(CachingDispatchAsync.class).in(Singleton.class);
    }

}
